<?php
/**
 * Created by PhpStorm.
 * User: 28768
 * Date: 2020/5/22
 * Time: 2:11
 */

namespace app\admin\model;

use think\model;

class User extends Model{

    // 设置当前模型对应的完整数据表名称
    protected $table = 'user';
    protected $pk = 'id';
    protected $auto = [];
    protected $insert = ['status' => 1];
    protected $autoWriteTimestamp = true;
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $readonly = [];
    //自定义初始化
    protected function initialize(){
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }
    //支持给字段设置类型自动转换
    protected $type = [
        'status'    =>  'integer',
    ];
    protected static function init(){
        User::beforeInsert(function ($user) {
            if ($user->status != 1) {
                return false;
            }
        });
    }
    public function getStatusAttr($value){
        $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
        return $status[$value];
    }
    public function getIsDeleteAttr($value){
        $isDelete = [1=>'删除',0=>'正常'];
        return $isDelete[$value];
    }
    public function setNameAttr($value){
        return strtolower($value);
    }

}